<template>
  <lay-out
    :show-header-color="true"
    :page-tag="pageTag"
    :attention="true"
    :title="title"
  >
    <!-- 实名 -->
    <label-list :data="labelData"></label-list>
    <!-- 落地 -->
    <portrait-list :data="portraitData"></portrait-list>
    <!-- 使用过的手机 -->
    <user-mobile :data="mobileData"></user-mobile>
    <!-- 涉及案件 -->
    <involved-in-case :data="caseData" title="涉案"></involved-in-case>
    <!-- 轨迹 -->
    <track-list title="轨迹" :data="otherData"></track-list>
    <!-- 通讯录好友 -->
    <friends-block title="好友" :data="otherData"></friends-block>
    <!-- 最近通话 -->
    <converse-file title="通讯记录" :data="otherData"></converse-file>
    <!-- 短信记录 -->
    <sms-logs-file :data="otherData"></sms-logs-file>
  </lay-out>
</template>

<script>
  import LayOut from '../../components/lay-out'
  import LabelList from '../../components/label-list'
  import PortraitList from '../../components/portrait-list'
  import UserMobile from './user-mobile'
  import ConverseFile from './converse-file'
  import SmsLogsFile from './sms-logs-file'
  import InvolvedInCase from '../../components/involved-in-case'
  import FriendsBlock from './friends-block'
  import TrackList from './track-block'
  import request, {getQuery} from '../../helper/request'
  import {BASE64_TYPE} from '@/config'

  export default {
    name: 'phone',
    components: {
      LayOut,
      LabelList,
      PortraitList,
      UserMobile,
      ConverseFile,
      SmsLogsFile,
      InvolvedInCase,
      FriendsBlock,
      TrackList
    },
    mixins: [],
    computed: {},
    data() {
      return {
        // 页面标签
        pageTag: {
          type: '004',
          number: ''
        },
        // 标题
        title: {
          text: '',
          reg: ''
        },
        labelData: {
          title: '实名',
          num: '',
          // icon: '/static/icon/shiming.png',
          icon: '/static/icon/two.png',
          list: []
        },
        portraitData: {
          title: '落地',
          num: '',
          // icon: '/static/icon/luodi.png',
          icon: '/static/icon/two.png',
          list: []
        },
        // 使用过的手机
        mobileData: [],
        caseData: {
          title: '涉及警情/案件',
          num: '',
          icon: '/static/icon/case.png',
          list: []
        },
        // 其它数据 带页面条件过去
        otherData: {}
      }
    },
    methods: {
      /**
       * 页面初始化
       */
      getInitPage() {
        getQuery.call(this, {
          sjh: '13762890311'
        }).then(resParam => {
          this.getQueryMobile(resParam)
          this.getQueryCase(resParam)
          this.otherData = resParam
        })
      },
      /**
       * 查询 智能落地、实名、使用过的手机
       * @param param
       */
      getQueryMobile(param) {
        request('superRecord/mobile/zss', 'SC0422', param).then(res => {
          // 页面标签
          this.pageTag.number = res.sjh
          // 标题
          this.title = {
            text: res.sjh,
            reg: `${res.sjhmgsd}-${res.sjhyys}`
          }
          // 实名
          let SMList = []
          if (res.sjda.sm) {
            SMList = res.sjda.sm
          }
          this.labelData.num = SMList.length
          this.labelData.list = SMList.map(resSM => {
            return {
              name: resSM.xm,
              num: resSM.num
            }
          })
          // 落地
          let LDList = []
          if (res.znld) {
            LDList = res.znld
          }
          this.portraitData.num = LDList.length
          this.portraitData.list = LDList.map(resLD => {
            let bs = []
            if (resLD.bs && resLD.bs.length > 0) {
              for (let rbs in resLD.bs) {
                bs[rbs] = {
                  text: resLD.bs[rbs],
                  is: true
                }
              }
            }
            return {
              name: resLD.xm,
              img: resLD.xp ? `${BASE64_TYPE}${resLD.xp}` : '/static/default/head.png',
              num: resLD.sfzh.slice(-4),
              tip: bs
            }
          })
          // 使用过的手机
          let SYGList = []
          if (res.sjda.sygdsj) {
            SYGList = res.sjda.sygdsj
          }
          this.mobileData = SYGList.map(resSYG => {
            return {
              number: resSYG.imei,
              mobile: resSYG.qtsjh
            }
          })
        }).catch(err => {
          this.$toast(err.msg)
        })
      },
      /**
       * 查询 涉及案件
       * @param param
       */
      getQueryCase(param) {
        request('superRecord/mobile/sjjqaj', 'SC0423', param).then(res => {
          this.caseData.list = res.sjjqaj.map(resCase => {
            return {
              type: resCase.type,
              tableName: resCase.tableName,
              systemid: resCase.systemid,
              img: resCase.xp ? `${BASE64_TYPE}${resCase.xp}` : '/static/default/case.png',
              number: resCase.bh,
              name: resCase.mc,
              label: resCase.type === '0' ? '警情' : resCase.type === '1' ? '案件' : '其它',
              tags: resCase.ajzt && [
                {
                  text: resCase.ajzt,
                  is: true
                }
              ],
              time: resCase.jjsj || resCase.fasj,
              address: resCase.jjdw || resCase.fadd
            }
          })
        }).catch(err => {
          this.$toast(err.msg)
        })
      }
    },
    watch: {
      '$route'(to, from) {
        // 对路由变化作出响应...
        this.getInitPage()
      }
    },
    mounted() {
    },
    created() {
      this.getInitPage()
    }
  }
</script>

<style scoped>

</style>
